package com.situ.mall.controller;

import com.situ.mall.pojo.Admin;
import com.situ.mall.pojo.Order;
import com.situ.mall.pojo.OrderItem;
import com.situ.mall.pojo.query.AdminQuery;
import com.situ.mall.pojo.query.OrderQuery;
import com.situ.mall.service.IOrderService;
import com.situ.mall.util.PageResult;
import com.situ.mall.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private IOrderService orderService;
    @RequestMapping("/list")
    public PageResult<Order> list(OrderQuery orderQuery){
        PageResult<Order> pageResult = orderService.list(orderQuery);
        return pageResult;
    }

    @RequestMapping("/deleteById")
    public Result deleteById(Long orderNo){
        orderService.deleteById(orderNo);
        return Result.ok("删除成功");
    }

    @RequestMapping("/deleteAll")
    public Result deleteAll(Long[] ids){
        orderService.deleteAll(ids);
        return Result.ok("删除成功");
    }

    @RequestMapping("/add")
    public Result add(Order order){
        orderService.add(order);
        return Result.ok("添加成功");
    }

    @RequestMapping("/orderItem")
    public Result orderItem(Long orderNo){
        System.out.println("OrderController.orderItem");
        System.out.println("orderNo:      ------"+orderNo);
        List<OrderItem> list = orderService.selectByOrderNo(orderNo);
        return Result.ok(list);
    }

    @RequestMapping("/shipping")
    public Result shipping(Long orderNo,Integer status){
        System.out.println("OrderController.shipping");
        if(status >= 3){
            return Result.error("商品已发货");
        }
        else if(status >= 0){
            orderService.changeStatus(orderNo,3);
            return Result.ok("发货成功");
        }
        return Result.error();
    }
}
